<template>
    <!-- 总包签证确认归档 -->
    <base-breadcrumb :title="$route.meta.title">
        <!-- 搜索 -->
        <searchData :searchData="searchArr" @search="search"></searchData>
        <!-- 表格 -->
        <a-card :bordered="false">
            <!-- <title-name :title="$route.meta.title"></title-name> -->
            <a-button class="mb12" icon="plus" type="primary" @click="handleManage(2)" v-btnPermission="'bm_028_add_01'">新增</a-button>
            <a-alert class="mb12" type="info" show-icon>
                <template slot="message">
                    <span>
                        完成份数：<a>{{ SummaryData.number || 0}}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                        报送金额(含税)(万元)：<a>{{ SummaryData.submitMoneyHaveVat || 0 }}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                        业主审定金额(含税)(万元)：<a>{{ SummaryData.confirmAmountHas || 0 }}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                        对应成本(含税)(万元)：<a>{{ SummaryData.correspondingCostHaveVat || 0}}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>利润率(%)：<a>{{ SummaryData.profitRate || 0 }}</a>
                    </span>
                </template>
            </a-alert>
            <!-- 表格 -->
            <list-table
                ref="table"
                tableLayout="fixed"
                size="default"
                rowKey="id"
                :columns="columns"
                :request="loadData"
                :page-keys="['pageNum', 'pageSize','totalSize']"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
            >
                <template slot="action" slot-scope="text, record">
                    <MoreButton>
                    <a @click="handleManage(0, record)" v-btnPermission="'bm_028_loo_04'">查看</a>
                    <span v-btnPermission="'bm_028_edi_02'"   v-if="record.auditStatus*1!==1 && record.auditStatus*1 !== 3 && record.auditStatus*1!== 4" >
                        <a @click="handleManage(1, record)">编辑</a>
                        </span>
                    <span v-if="record.auditStatus*1 === 1 && userId === record.creatorId&&hideBuquBtn()">
                        <a @click="handleUndo({ id: record.id})">撤销</a>
                    </span>
                    <span v-btnPermission="'bm_028_tov_05'" v-if="record.auditStatus*1 === 3">
                        <a @click="handleInvalid({ id: record.id})">作废</a>
                    </span>
                      <template v-if="record.auditStatus*1 === 5">
                        <template>
                          <!-- 删除 -->
                            <span v-btnPermission="'bm_028_del_03'"   v-if="record.auditStatus*1 ===0 || record.auditStatus*1 ===5">
                                <a @click="handleRemoveParams({ id: record.id })">删除</a>
                            </span>

                            <span v-btnPermission="'bm_028_loo_04'"  v-if="
                                record.auditStatus*1  === 3 ||
                                record.auditStatus*1 === 1 ||
                                record.auditStatus*1 === 5||
                                record.auditStatus*1  === 4
                                ">
                                <approval-button :id="record.id" :status="getStatus(record.auditStatus)" />
                            </span>
                        </template>
                      </template>
                      <template v-else>
                        <!-- 删除 -->
                        <span v-btnPermission="'bm_028_del_03'"   v-if="record.auditStatus*1 ===0 || record.auditStatus*1 ===5">
                            <a @click="handleRemoveParams({ id: record.id })">删除</a>
                        </span>

                        <span v-btnPermission="'bm_028_loo_04'"  v-if="
                            record.auditStatus*1  === 3 ||
                            record.auditStatus*1 === 1 ||
                            record.auditStatus*1 === 5||
                            record.auditStatus*1  === 4
                            ">
                            <approval-button :id="record.id" :status="getStatus(record.auditStatus)" />
                        </span>
                      </template>
                    </MoreButton>
                </template>
                <template slot="auditStatus"  slot-scope="text, record">
                    <list-status :status="getStatus(record.auditStatus)" conversion="en" :is-approval="true" :text="getStatus(text)" />
                </template>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import { getVisaConfimlList, delVisaConfimlList,getTopTotal,visaConfirmCancelProcess,visaConfirmRevoke} from '@/api/businessAffairs/visaConfirm' // api
import BasePage from '@/views/basePage' // 基础配置
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { types,typeListApproval} from './model'
import Item from '@/components/AvatarList/Item.vue'
const searchArr = [
    // 搜索框
    {
      name: '所属单位',
      valueKey: 'searchQuery',
      type: OrgTreeSelect,
    },
    // {name: '所属分公司', valueKey: 'branchComId', type: SelectSubCompany},
    // {name: '所属项目',keyValue: 'branchComId',valueKey: 'projectId',type: SelectProject},
    {name: '签证名称',type: 'input', value: 'visaName'},
    {name: '类型',value: 'typleId',type: 'select',data: types},
    {name: '报送时间',type: 'dateRange',value: 'submitTime',
        attr: {
            rangeFormat: ['submitStartTime', 'submitEndTime']
        }
    },
    {name: '填报人',type: 'input',value: 'modifiedName'},
    {name: '填报时间',type: 'dateRange',value: 'modifiedTime',
        attr: {
            rangeFormat: ['startTime', 'endTime']
        }
    },
    {name: '状态',value: 'auditStatus',type: 'select',data: typeListApproval}
]

const columns = [
    // {title: '序号',width: 80,dataIndex: 'index',
    //     customRender() {
    //         return arguments[2] + 1
    //     }
    // },
    {title: '所属分公司',dataIndex: 'branchComName',ellipsis: true,width: 150,},
    {title: '所属项目',dataIndex: 'projectName',ellipsis: true,width: 150,},
    {title: '签证名称',dataIndex: 'visaName',ellipsis: true,width: 180,},
    {title: '类型',dataIndex: 'typleName',ellipsis: true,width: 150,},
    {title: '签证编号',dataIndex: 'visaCode',ellipsis: true,width: 150,},
    {title: '报送时间',dataIndex: 'submitTime',ellipsis: true,width: 150,},
    {title: '报送金额(含税)(万元)',dataIndex: 'submitMoneyHaveVat',ellipsis: true,width: 180,},
    {title: '业主审批(含税)(万元)',dataIndex: 'confirmAmountHas',ellipsis: true,width: 180,},
    {title: '对应成本(含税)(万元)',dataIndex: 'correspondingCostHaveVat',ellipsis: true,width: 180,},
    {title: '利润率%',dataIndex: 'profitRate',ellipsis: true,width: 150,},
    {title: '填报人',dataIndex: 'modifiedName',width: 250,},
    {title: '填报时间',dataIndex: 'modifiedTime',ellipsis: true, width: 200,},
    {title: '状态',dataIndex: 'auditStatus',scopedSlots: { customRender: 'auditStatus' },width: 150,},
    {title: '操作',dataIndex: 'action',width: '280px',align: 'center',scopedSlots: { customRender: 'action' },  fixed: 'right',}
]
export default {
    name: 'a' + Date.now(),
    extends: new BasePage(),
    components: {
        STable,
        Item
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            userId: JSON.parse(sessionStorage.getItem('ycloud-user_info')).id,
            queryParam: {}, // 查询参数
            statistics: { totalAutoContractFee: 0, totalTentativelyUpProfitFee: 0, totalTentativelyUpRate: 0 }, //统计
            loadData: async (parameter) => {
                const requestParameters = Object.assign({}, parameter, { param: this.queryParam })
                return getVisaConfimlList(requestParameters).then((res) => {
                 return res;
                })
            },
            removeApi: { remove: delVisaConfimlList, invalid: visaConfirmRevoke, undo: visaConfirmCancelProcess },// api
            SummaryData:{
                confirmAmountHas:0,
                correspondingCostHaveVat:0,
                number:0,
                profitRate:0,
                submitMoneyHaveVat:0
            }    //汇总
        }
    },
    methods: {
        // 搜索
        search(value) {
            value && (this.queryParam = value)
            this.$refs.table.refresh(true)
            this.getSummaryData(this.queryParam);
        },
        getStatus(str){
            let  strText = '';
             switch (str) {
                case 0:
                    strText = "DRAFT";
                    break;
                case 1:
                    strText = "SUBMITTED";
                    break;
                case 2:
                    strText = "UPLOAD";
                    break;
                case 3:
                    strText = "PAST";
                    break;
                case 4:
                    strText = "ABOLISH";
                    break;
                case 5:
                    strText = "REJECTED";
                    break;
                default:
                    strText = "";
            }
            return strText;
        },
       async getSummaryData() {
           let reqData = await getTopTotal(this.queryParam);
           if(reqData.msg=='成功'){
            this.SummaryData = reqData.data;
           }

        },
        // 操作栏
        handleManage(type, record) {
            let query = {
                editModel: type
            }
            if (record && record.id) {
                query.id = record.id
            }
            this.$router.push({
                name: 'updateVisaConfirm',
                query
            })
        }
    },
   created(){
      this.getSummaryData();
    }
}
</script>
